package wxshop.web.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import wxshop.api.admin.model.wx.WxUserInfo;
import wxshop.api.user.model.OrderRecord;
import wxshop.api.user.model.WxUnionID;
import wxshop.api.user.model.Xx;
import wxshop.api.user.service.BalancesService;
import wxshop.api.user.service.SelectService;
import wxshop.api.user.service.UserService;
import wxshop.web.user.dto.FormResult;

import javax.servlet.http.HttpSession;

/**
 * Created by yvdedu.com on 2018/1/26.
 */
@SuppressWarnings("SpringJavaAutowiringInspection")
@RestController
@RequestMapping("xx")
public class XxController {
	
	@Autowired
	private SelectService selectService;
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private BalancesService balancesService;
	
	@Autowired
	private HttpSession session;
	
	//openid信息
	@RequestMapping(value = "/userInfo",method = RequestMethod.POST)
	public Object oopenid(WxUserInfo wxUserInfo) {
		userService.insertUserInfo(wxUserInfo);
		return new FormResult(true,"插入成功");
	}
	
	//信息
	@RequestMapping(method = RequestMethod.GET)
	public Object xx() {
		return selectService.getQueryUseres((Integer) session.getAttribute("id"));
	}
	
	//收货地址信息
	@RequestMapping(value = "/info",method = RequestMethod.GET)
	public Object xxInfo() {
		return selectService.getQueryInfoes((Integer) session.getAttribute("id"));
	}
	
	//微信个人信息
	@RequestMapping(value = "/wxname",method = RequestMethod.GET)
	public Object wxName() {
		return userService.getNickName(1);
	}
	
	
	
	//xi修改信息
	@RequestMapping(value = "/info/update",method = RequestMethod.GET)
	public Object xxInfoUpdate() {
//		return selectService.getQueryInfoes((Integer) session.getAttribute("id"));
		return null;
	}
	
	@RequestMapping(value = "/info/"+"{id:\\d+}",method = RequestMethod.GET)
	public Xx read(@PathVariable("id") int id) {
		return selectService.getQueryInfoOnes(id);
	}
	
	//订单记录
	@RequestMapping(value = "/ddjl", method = RequestMethod.GET)
	public Object userOrderRecord() {
		return balancesService.queryOrderRecord(new OrderRecord((Integer) session.getAttribute("id")));
	}
	
	//订单记录购物车
	@RequestMapping(value = "/gwc", method = RequestMethod.GET)
	public Object userGwcOrderRecord() {
		return balancesService.queryOrderRecord(new OrderRecord(1,(Integer) session.getAttribute("id")));
	}
	
	
}
